# Maintainer: Andy Postnikov <apostnikov@gmail.com>
pkgname=php84-pecl-xhprof
_extname=xhprof
pkgver=2.3.10
pkgrel=1
pkgdesc="A Hierarchical Profiler for PHP 8.4 - PECL"
url="https://pecl.php.net/package/xhprof"
arch="all"
license="Apache-2.0"
_phpv=84
_php=php$_phpv
depends="$_php-common"
makedepends="$_php-dev"
_assetsdepends="$_php-ctype graphviz ghostscript-fonts"
subpackages="$pkgname-assets::noarch"
#source="php-pecl-$_extname-$pkgver.tgz::https://pecl.php.net/get/$_extname-$pkgver.tgz"
source="php-$_extname-$pkgver.tgz::https://github.com/longxinH/xhprof/archive/refs/tags/v$pkgver.tar.gz"
builddir="$srcdir/$_extname-$pkgver/extension"
provides="$_php-xhprof=$pkgver-r$pkgrel" # for backward compatibility
replaces="$_php-xhprof" # for backward compatibility

install_if="php-$_extname php$_phpv"

build() {
	phpize$_phpv
	./configure --with-php-config=php-config$_phpv
	make
}

check() {
	[ $CARCH = s390x ] && rm -fr tests/xhprof_005.phpt # sleeping longer in CI
	make NO_INTERACTION=1 REPORT_EXIT_STATUS=1 TESTS=--show-diff test
	$_php -d extension=modules/$_extname.so --ri $_extname
}

package() {
	make INSTALL_ROOT="$pkgdir" install
	local _confdir="$pkgdir"/etc/$_php/conf.d
	install -d $_confdir
	cat > $_confdir/$_extname.ini <<-EOF
		extension=$_extname
		xhprof.output_dir=/tmp
	EOF
}

assets() {
	pkgdesc="A Hierarchical Profiler for PHP (UI assets)"
	depends="$_assetsdepends"
	provides="$_php-xhprof-assets=$pkgver-r$pkgrel" # for backward compatibility
	replaces="$_php-xhprof-assets" # for backward compatibility

	local _assetsdir="$subpkgdir"/usr/share/$_php/xhprof
	install -d $_assetsdir
	cp -R "$builddir"/../xhprof_lib $_assetsdir
	cp -R "$builddir"/../xhprof_html $_assetsdir
	cp -R "$builddir"/../examples $_assetsdir
}

sha512sums="
e12d3b3771e62f1e31171ded5cddada2c3827f0837aaa76fb1ea7cb74f0031a51f62290a0bfc36dd78f64066d94b25513ef354a6528d1d35f170dbc9d586f5fb  php-xhprof-2.3.10.tgz
"
